<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1.0">
	<title>好友管理</title>
    <!-- Bootstrap core CSS -->
    <link href="/static/bootstrap/css/bootstrap2.min.css" rel="stylesheet">
	<link href="/static/fullcalendar/fullcalendar.min.css" rel="stylesheet">
	<link href="/static/fullcalendar/fullcalendar.print.min.css" rel="stylesheet" media="print">
	<link href="/static/jquery-ui-1.10.4.custom/css/base/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">
	<link href="/static/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css" rel="stylesheet">
	<link href="/static/fullcalendar/lib/cupertino/jquery-ui.min.css" rel="stylesheet">
	<link href="/static/artDialog/css/ui-dialog.css" rel="stylesheet">
	<link href="/static/wickedpicker/dist/wickedpicker.min.css" rel="stylesheet">
	<script src="/static/jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
	<script src="/static/fullcalendar/lib/jquery.min.js"></script>
	<script src="/static/fullcalendar/lib/jquery-ui.min.js"></script>
	<script src="/static/fullcalendar/lib/moment.min.js"></script>
	<script src="/static/fullcalendar/fullcalendar.js"></script>
	<script src="/static/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="/static/artDialog/dist/dialog-min.js"></script>
	<script src="/static/bootstrap/js/bootstrap.min.js"></script>
	<script src="/static/wickedpicker/dist/wickedpicker.min.js"></script>
	<script src="/static/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
	<script src="/static/bootstrap-datepicker/dist/locales/bootstrap-datepicker.zh-CN.min.js"></script>
	<style>
		body{
			margin:40px 40px;
			padding:0;
			background:white;
			font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
			font-size: 14px;
		}
	</style>
	<script>
        {% if jumpRes %}
            alert("{{ jumpRes }}");
        {% endif %}

        //--删除好友
	function colDelete(deleteId) {
		if(confirm("确认删除？")) {
            $.ajax({
                type: "POST",//方法类型
                dataType: "text",//预期服务器返回的数据类型
                url: "/colleague/colleague_delete",//url
                data:"{\"colleague_id\":\""+deleteId+"\"}",
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    alert(result);
                    window.location.reload();
                },
                error: function () {
                    alert("删除失败！");
                    window.location.reload();
                }
            });
        }
	};

	function colAdd() {
	    var nickName = $('#nickname').val();
		if(confirm("确认添加？")) {
            $.ajax({
                type: "POST",//方法类型
                dataType: "text",//预期服务器返回的数据类型
                url: "/colleague/colleague_add",//url
                data:"{\"nickName\":\""+nickName+"\"}",
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result == "SUCCESS") {
                        alert("添加成功！");
                        window.location.reload();
                    }
                    else{
                        alert("好友信息错误！");
                        window.location.reload();
                    }

                },
                error: function () {
                    alert("好友信息出现错误！");
                    window.location.reload();
                }
            });
        }
	};
    </script>
</head>
<body style="background: url('/static/imgs/background.jpg');background-repeat:no-repeat;background-size:cover">
    <!-- 导航栏 -->
    <nav class="navbar navbar-fixed-top navbar-inverse" style="height: 40px;" >
      <div class="container">
        <div class="navbar-header" style="height: 40px;">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="/user/to_user_index_page">主页</a></li>
            <li><a href="/schedule/toScheduleList">代办列表</a></li>
            <li><a href="/colleague/colleague_list">好友管理</a></li>
            <li><a href="/group/user_group_list">小组管理</a></li>
            <li><a href="#" data-toggle="modal"  data-target="#updateUserInfo">欢迎您 {{ session["user_nickname"] }}</a></li>
            <li><a href="/user/user_logout">注销</a></li>
          </ul>
        </div><!-- /.nav-collapse -->
      </div><!-- /.container -->
    </nav><!-- /.navbar -->

     <!-- 修改用户信息 -->
<div class="modal fade" id="updateUserInfo" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
	            </div>
                <div class="modal-body">
                      <div class="form-group">
					    <label for="exampleInput1">用户名</label>
					    <input type="text" class="form-control" id="update_user_name" value="{{ session['user_name'] }}">
					  </div>
                      <div class="form-group">
					    <label for="exampleInput1">密码</label>
					    <input type="text" class="form-control" id="update_user_pwd" value="{{ session['user_pwd'] }}">
					  </div>
					  <div class="form-group">
					    <label for="exampleInput1">昵称</label>
					    <input type="text" class="form-control" id="update_user_nickname" value="{{ session['user_nickname'] }}">
					  </div>
                      <div class="form-group">
					    <label for="exampleInput1">性别</label>
					    <input type="text" class="form-control" id="update_user_sex" value="{{ session['user_sex'] }}">
					  </div>
                      <div class="form-group">
					    <label for="exampleInput1">邮箱</label>
					    <input type="text" class="form-control" id="update_user_email" value="{{ session['user_email'] }}">
					  </div>
					  <div class="form-group">
					    <label for="exampleInput1">电话</label>
					    <input type="text" class="form-control" id="update_user_phone" value="{{ session['user_phone'] }}">
					  </div>
	            </div>
                <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
	                <button type="button" id="btnSubmit" class="btn btn-primary" onclick="updateUser()">修改</button>
	            </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
    <script>
	function updateUser() {
	    var user_name = $('#update_user_name').val();
	    var user_pwd = $('#update_user_pwd').val();
	    var user_nickname = $('#update_user_nickname').val();
	    var user_sex = $('#update_user_sex').val();
	    var user_email = $('#update_user_email').val();
	    var user_phone = $('#update_user_phone').val();
		if(confirm("确认修改？")) {
            $.ajax({
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/user/user_data_update",//url
                data:"{\"user_sex\":\""+user_sex+"\",\"user_name\":\""+user_name+"\",\"user_pwd\":\""+user_pwd+"\",\"user_nickname\":\""+user_nickname+"\",\"user_email\":\""+user_email+"\",\"user_phone\":\""+user_phone+"\"}",
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    alert(result);
                    window.location.reload();
                },
                error: function () {
                    alert("修改用户信息成功！");
                    window.location.reload();
                }
            });
        }
	};

	//搜索用户
	function selectUser() {
	    var user_name = $('#select_user_name').val();
        window.location.href='/colleague/colleague_select?user_name='+user_name;
	};



    </script>

    <!-- 导航栏结束 -->

    <br>

    <div class="container">
    <div class="col-sm-12" >
    <button type="button" id="btnAdd" data-toggle="modal" data-target="#selectModal"  class="btn btn-primary">查找好友</button>
    <button type="button" id="btnAdd" data-toggle="modal" style="float:right;" data-target="#permissionModal"  class="btn btn-primary">权限设置</button>
    <table id="selectRes" class="table table-hover">
        {%  if colleague_list %}
                <tr>
                    <td><h3>查找结果</h3></td>
                </tr>
            {% for item in colleague_list %}
                <tr>
                    <td>{{ item.username }}</td>
                    <td>{{ item.nickname }}</td>
                    <td>{{ item.sex }}</td>
                    <td>{{ item.email }}</td>
                    <td>{{ item.phone }}</td>
                    <td>
                        <a href="/colleague/to_colleague_schedule?colleague_id={{ item.id }}"><button type="button" class="btn btn-primary">查看好友日程</button></a>
                        <a href="/colleague/to_colleague_events?colleague_id={{ item.id }}"><button type="button" class="btn btn-primary">查看好友待办</button></a>
                    </td>
                </tr>
            {% endfor %}
        {% endif %}
    </table>


    <br/>
    <!-- 所有用户列表 -->
    <table class="table table-hover">
        {%  if user_info_list %}
                <tr>
                    <td>好友名称</td>
                    <td>昵称</td>
                    <td>性别</td>
                    <td>邮箱</td>
                    <td>电话</td>
                    <td>操作</td>
                </tr>
            {% for item in user_info_list %}
                <tr>
                    <td>{{ item.username }}</td>
                    <td>{{ item.nickname }}</td>
                    <td>{{ item.sex }}</td>
                    <td>{{ item.email }}</td>
                    <td>{{ item.phone }}</td>
                    <td>
                        <a href="/colleague/to_colleague_schedule?colleague_id={{ item.id }}"><button type="button" class="btn btn-primary">查看好友日程</button></a>
                        <a href="/colleague/to_colleague_events?colleague_id={{ item.id }}"><button type="button" class="btn btn-primary">查看好友待办</button></a>
                    </td>
                </tr>
            {% endfor %}
        {% else %}
            <a href="">暂无同事，点击添加</a>
        {% endif %}
    </table>
    </div>
    </div>



   <!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">添加同事</h4>
	            </div>
     <div class="modal-body">
					  <div class="form-group">
					    <label for="exampleInput1">同事昵称</label>
					    <input type="text" class="form-control" id="nickname" placeholder="同事昵称">
					  </div>
	            </div>
      <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="btnSubmit" class="btn btn-primary" onclick="colAdd()">添加</button>
	            </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!-- 搜索用户 -->
<div class="modal fade" id="selectModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">查找同事</h4>
	            </div>
     <div class="modal-body">
					  <div class="form-group">
					    <label for="exampleInput1">请输入要查找的同事</label>
					    <input type="text" class="form-control" id="select_user_name" placeholder="请输入要查找的同事">
					  </div>
	            </div>
      <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="btnSubmit" class="btn btn-primary" onclick="selectUser()">查找</button>
	            </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!-- 设置权限 -->
<div class="modal fade bs-example-modal-lg" style="width:auto;overflow:scroll" id="permissionModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">权限设置</h4>
	            </div>
     <div class="modal-body" >
					  <table class="table table-hover">
                    {%  if user_info_list %}
                            <tr>
                                <td>好友名称</td>
                                <td>昵称</td>
                                <td>性别</td>
                                <td>邮箱</td>
                                <td>电话</td>
                                <td>权限</td>
                            </tr>
                        {% for item in user_info_list %}
                            <tr>
                                <td>{{ item.username }}</td>
                                <td>{{ item.nickname }}</td>
                                <td>{{ item.sex }}</td>
                                <td>{{ item.email }}</td>
                                <td>{{ item.phone }}</td>
                                <td>
                                   <select class="form-control" id="{{ item.username }}" onchange="updatePermission('{{ item.username }}','{{ item.id }}')">
                                      <option name="{{ item.username }}" id="{{ item.username+'1' }}"  value="0">可查看</option>
                                      <option name="{{ item.username }}" id="{{ item.username+'2' }}"  value="1">可修改</option>
                                      <option name="{{ item.username }}" id="{{ item.username+'3' }}"  value="2">不可操作</option>
                                    </select>
                                    <script>
                                        document.getElementById("{{ item.username }}").selectedIndex = {{ item.permission }};
                                    </script>
                                        <script>
                                            function updatePermission(id,userid) {
                                                var permission =$("#"+id+" option:selected").val();
                                                {#var opt=$("#{{ item.username }}").val();#}
                                                $.ajax({
                                                    type: "POST",//方法类型
                                                    dataType: "text",//预期服务器返回的数据类型
                                                    url: "/colleague/colleague_permission_update",//url
                                                    data:"{\"user_id\":\""+userid+"\",\"user_permission\":\""+permission+"\"}",
                                                    success: function (result) {
                                                        console.log(result);//打印服务端返回的数据(调试用)
                                                        if (result == "SUCCESS") {
                                                            alert("修改成功！");
                                                        }
                                                    },
                                                    error: function () {
                                                        alert("权限修改失败！");
                                                        window.location.reload();
                                                    }
                                                });
                                            }
                                        </script>
                                </td>

                            </tr>
                        {% endfor %}
                    {% else %}
                        <a href="">暂无同事，点击添加</a>
                    {% endif %}
                </table>
	            </div>
                <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	            </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>